﻿// 用户主页

var session;

//根据url获取用户名
var parameter = window.location.href.split("?")[1];
var parameterList = parameter.split("&");
var username = decodeURIComponent(parameterList[0]);

// 将用户名带入iframe_right URL中
$(document).ready(function (){
    var iframe_right_src = $(window.parent.document).find("#iframe_right").attr("src");
    $("#iframe_right").attr('src',iframe_right_src + "?" + username + "&&&&&&&1&1&20");
});

//iframe自适应高度
var iframe_left= document.getElementById("iframe_left");
var iframe_right= document.getElementById("iframe_right");
function changeFrameHeight(){
    iframe_left.height=document.documentElement.clientHeight-60;
    iframe_right.height=document.documentElement.clientHeight-60;
}
window.onresize=function(){
    changeFrameHeight();
};

//根据用户名获取其真实姓名
var realname;
var imgurl;
$.ajax({
    type: "post",
    url: "/ysfwpt/selectUserInfoByName",
    async: false,
    data: {
        username: username
    },
    success: function(data) {
        // console.log("success");
        // console.log(data);
        session = $("#username").html();
        if(data.user.imgurl != "" && data.user.imgurl != undefined ){
            $("#userphoto").attr("src",data.user.imgurl);
        }
        if(data.user.realname != session){
            alert("用户信息过期，请重新登录！");
            window.location.href = "login";
        }
    }
});

//点击用户中心或药事服务
$(".menu_list").bind("click",function(){
    $(this).css("border-bottom","3px solid #E6E6E6");
    $(this).siblings().css("border-bottom","3px solid transparent");
});

$("#user_center").bind("click",function(){
    $("#iframe_left").attr("src","/ysfwpt/user_center_catalog");
});
$("#ys_service").bind("click",function(){
    $("#iframe_left").attr("src","/ysfwpt/ys_service_catalog");
});

//点击用户头像
$("#quit").click(function (e){
    e.stopPropagation(); //阻止冒泡 
    if($("#quitlist").is(':visible')){
        $("#quitlist").slideUp(300);
    }
    else{
        $("#quitlist").slideDown(300);
        $(document).one("click",function(){
            $("#quitlist").slideUp(300);
        });
    }
});
iframe_right.onload = function() {
    iframe_right.contentDocument.onclick = function () {
        $("#quitlist").slideUp(300);
    }
};

//个人信息
$("#userinfo").bind("click",function(){
    $("#iframe_right").attr("src","/ysfwpt/ysfwpt_home_userinfo?" + username);
});

//修改密码
$("#changepsw").bind("click",function(){
    $("#iframe_right").attr("src","/ysfwpt/ysfwpt_home_password?" + username);
});

//退出
$("#quitlogin").click(function (){
    window.location.href = "login";
});